home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / pine3.92 / pico / ansi.c next >
C/C++ Source or Header  |  1996-03-14  |  4KB  |  164 lines

  1. #if    !defined(DOS)
  2. static char rcsid[] = "$Id: ansi.c,v 4.9 1996/03/15 07:41:11 hubert Exp $";
  3. #endif
  4. /*
  5.  * Program:    ANSI terminal driver routines
  6.  *
  7.  *
  8.  * Michael Seibel
  9.  * Networks and Distributed Computing
  10.  * Computing and Communications
  11.  * University of Washington
  12.  * Administration Builiding, AG-44
  13.  * Seattle, Washington, 98195, USA
  14.  * Internet: mikes@cac.washington.edu
  15.  *
  16.  * Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  17.  *
  18.  * Pine and Pico are registered trademarks of the University of Washington.
  19.  * No commercial use of these trademarks may be made without prior written
  20.  * permission of the University of Washington.
  21.  * 
  22.  * Pine, Pico, and Pilot software and its included text are Copyright
  23.  * 1989-1996 by the University of Washington.
  24.  * 
  25.  * The full text of our legal notices is contained in the file called
  26.  * CPYRIGHT, included with this distribution.
  27.  *
  28.  */
  29. /*
  30.  * The routines in this file provide support for ANSI style terminals
  31.  * over a serial line. The serial I/O services are provided by routines in
  32.  * "termio.c". It compiles into nothing if not an ANSI device.
  33.  */
  34.  
  35. #define    termdef    1            /* don't define "term" external */
  36.  
  37. #include        <stdio.h>
  38. #include    "pico.h"
  39. #include    "estruct.h"
  40. #include        "edef.h"
  41. #include        "osdep.h"
  42.  
  43. #if     ANSI_DRIVER
  44.  
  45. #define    MARGIN    8            /* size of minimim margin and    */
  46. #define    SCRSIZ    64            /* scroll size for extended lines */
  47. #define    MROW    2            /* rows in menu                 */
  48. #define BEL     0x07                    /* BEL character.               */
  49. #define ESC     0x1B                    /* ESC character.               */
  50.  
  51. extern  int     ttopen();               /* Forward references.          */
  52. extern  int     ttgetc();
  53. extern  int     ttputc();
  54. extern  int     ttflush();
  55. extern  int     ttclose();
  56. extern  int     ansimove();
  57. extern  int     ansieeol();
  58. extern  int     ansieeop();
  59. extern  int     ansibeep();
  60. extern  int     ansiopen();
  61. extern    int    ansirev();
  62. /*
  63.  * Standard terminal interface dispatch table. Most of the fields point into
  64.  * "termio" code.
  65.  */
  66. #if defined(VAX) && !defined(__ALPHA)
  67. globaldef
  68. #endif
  69. TERM    term    = {
  70.         NROW-1,
  71.         NCOL,
  72.     MARGIN,
  73.     SCRSIZ,
  74.     MROW,
  75.         ansiopen,
  76.         ttclose,
  77.         ttgetc,
  78.         ttputc,
  79.         ttflush,
  80.         ansimove,
  81.         ansieeol,
  82.         ansieeop,
  83.         ansibeep,
  84.     ansirev
  85. };
  86.  
  87. ansimove(row, col)
  88. {
  89.         ttputc(ESC);
  90.         ttputc('[');
  91.         ansiparm(row+1);
  92.         ttputc(';');
  93.         ansiparm(col+1);
  94.         ttputc('H');
  95. }
  96.  
  97. ansieeol()
  98. {
  99.         ttputc(ESC);
  100.         ttputc('[');
  101.         ttputc('K');
  102. }
  103.  
  104. ansieeop()
  105. {
  106.         ttputc(ESC);
  107.         ttputc('[');
  108.         ttputc('J');
  109. }
  110.  
  111. ansirev(state)        /* change reverse video state */
  112.  
  113. int state;    /* TRUE = reverse, FALSE = normal */
  114.  
  115. {
  116.     static int PrevState = 0;
  117.  
  118.     if(state != PrevState) {
  119.         PrevState = state ;
  120.         ttputc(ESC);
  121.         ttputc('[');
  122.         ttputc(state ? '7': '0');
  123.         ttputc('m');
  124.     }
  125. }
  126.  
  127. ansibeep()
  128. {
  129.         ttputc(BEL);
  130.         ttflush();
  131. }
  132.  
  133. ansiparm(n)
  134. register int    n;
  135. {
  136.         register int    q;
  137.  
  138.         q = n/10;
  139.         if (q != 0)
  140.                 ansiparm(q);
  141.         ttputc((n%10) + '0');
  142. }
  143.  
  144. #endif
  145.  
  146. ansiopen()
  147. {
  148. #if     V7
  149.         register char *cp;
  150.         char *getenv();
  151.  
  152.         if ((cp = getenv("TERM")) == NULL) {
  153.                 puts("Shell variable TERM not defined!");
  154.                 exit(1);
  155.         }
  156.         if (strcmp(cp, "vt100") != 0) {
  157.                 puts("Terminal type not 'vt100'!");
  158.                 exit(1);
  159.         }
  160. #endif
  161.     revexist = TRUE;
  162.         ttopen();
  163. }
  164.